package Controller.Goods;

import Dao.GoodsCategoryDao;
import Dto.Goods;
import Service.GoodsService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "preUpdateGoods", value = "/preUpdateGoods")
public class PreUpdateGoods extends HttpServlet {
    private GoodsService goodsService = new GoodsService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        try {
            GoodsCategoryDao dao = new GoodsCategoryDao();
            List<String> list = dao.selectCategory();
            Goods goods = goodsService.preUpdateGoods(id);
            request.setAttribute("list",list);
            request.setAttribute("goods",goods);
            request.getRequestDispatcher("/updateGoods.jsp").forward(request,response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}